﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UCL.Powersource;
using UCL.Powersource.Analysis;
using UCL.Powersource.ViewModels;
using UCL.Powersource.ViewModels.Analysis;

namespace BaseStatisticControlLibrary.ViewModels
{
    [Export(typeof(IStatisticViewModel))]
    [Export(typeof(OverallStatisticsViewModel))]
    public class OverallStatisticsViewModel : UCL.Powersource.ViewModels.Analysis.StatisticViewModelBase
    {
        public OverallStatisticsViewModel()
            : base(StatisticViewModelTypes.MultipleTeams_MultipleTimeFrames, true, true, false)
        { }

        public override string Label
        {
            get { return "Statistics - overview"; }
        }

        public override string Title
        {
            get { return "Statistics - overview"; }
        }

        public override string Description
        {
            get { return "Dummy Code Index Statistic - Description"; }
        }



        #region CountOfStatistics


        /// <summary>
        /// Property CountOfStatistics. TODODOC: Insert appropriate summary here
        /// </summary>
        public int CountOfStatistics
        {
            get { return RegisteredStatistics == null ? 0 : RegisteredStatistics.Count; }
            //set { if (_CountOfStatistics == value) return; _CountOfStatistics = value; CountOfStatistics_RecalculateDependencies(); }
        }

        private void CountOfStatistics_RecalculateDependencies()
        {
            //Recalculate all properties here

            //NotifyOfPropertyChange is usually placed as last statement - first change all dependencies and then fire property change
            NotifyOfPropertyChange(() => CountOfStatistics);
        }

      

        #endregion


        #region CountOfReportings

        /// <summary>
        /// Field storage for property CountOfReportings
        /// </summary>
        //private int _CountOfReportings = default(int);

        /// <summary>
        /// Property CountOfReportings. TODODOC: Insert appropriate summary here
        /// </summary>
        public int CountOfReportings
        {
            get { return IPowersourceExt.ReportingManager.StatisticViewModels.Count; }
            //set { if (_CountOfReportings == value) return; _CountOfReportings = value; CountOfReportings_RecalculateDependencies(); }
        }

        private void CountOfReportings_RecalculateDependencies()
        {
            //Recalculate all properties here

            //NotifyOfPropertyChange is usually placed as last statement - first change all dependencies and then fire property change
            NotifyOfPropertyChange(() => CountOfReportings);
        }

        //private void CountOfReportings_Recalculate()
        //{
        //    _CountOfReportings = default(int);
        //    //Insert your code here

        //    CountOfReportings_RecalculateDependencies();
        //}

        #endregion



        protected override void Recalculate_Internal()
        {
            if (StatisticResultsTable != null) StatisticResultsTable.Dispose();
            StatisticResultsTable = new System.Data.DataTable();
            var dcName = new DataColumn("StatisticName", typeof(string)) { Caption = "Name of the statistic" };
            StatisticResultsTable.Columns.Add(dcName);

            var dcAss = new DataColumn("StatisticAssembly", typeof(string)) { Caption = "Name of the holding assemblyFile" };
            StatisticResultsTable.Columns.Add(dcAss);

            foreach (var it in RegisteredStatistics)
            {
                DataRow dr = StatisticResultsTable.NewRow();
                dr[dcName] = it.Value.Name;
                dr[dcAss] = it.Value.GetType().Assembly.GetName();
                StatisticResultsTable.Rows.Add(dr);
            }
        }


        public override bool CanRegisterStatistic(UCL.Powersource.Analysis.IStatistic statistic)
        {
            return true;
        }

        protected override bool OnActivating()
        {
            return true;
        }

        protected override bool OnDeactivating()
        {
            return true;
        }


    }
}
